package com.feature.learn.annotation;

/**
 * @Author: wangxc
 * @GitHub: https://github.com/vector4wang
 * @CSDN: http://blog.csdn.net/qqhjqs?viewmode=contents
 * @BLOG: http://vector4wang.tk
 * @wxid: BMHJQS
 */

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * http://www.importnew.com/14227.html#comments
 * https://www.cnblogs.com/huajiezh/p/5263849.html
 */
public class TestMain {
    public static void main(String[] args) {
        Class<AnnotatedClass> object = AnnotatedClass.class;
        // Retrieve all annotations from the class
        Annotation[] annotations = object.getAnnotations();
        for (Annotation annotation : annotations) {
            System.out.println(annotation);
        }

        // Checks if an annotation is present
        if (object.isAnnotationPresent(CustomAnnotationClass.class)) {

            // Gets the desired annotation
            Annotation annotation = object.getAnnotation(CustomAnnotationClass.class);

            System.out.println(annotation);

        }
        // the same for all methods of the class
        for (Method method : object.getDeclaredMethods()) {

            if (method.isAnnotationPresent(CustomAnnotationMethod.class)) {

                Annotation annotation = method.getAnnotation(CustomAnnotationMethod.class);

                System.out.println(annotation);

            }

        }



    }
}
